/**
 * 验证用户名不为空
 */
function checkUserName(){
	var userName = $.trim($("#username").val());
	var falg = true;
	if(userName == null || userName == "" || userName == "用户名"){
		layer.tips("请输入用户名", "#username", {tips: [2, "#E34127"],time: 500});
		falg = false;
	}
	return falg;
}

/**
 * 验证密码不为空
 */
function checkPassWord(){
	var password = $.trim($("#password").val());
	var falg = true;
	if(password == null || password == "" || password == "密码"){
		layer.tips("请输入密码", "#password", {tips: [2, "#E34127"],time: 500});
		falg = false;
	}
	return falg;
}


/**
 * 验证验证码不为空
 */
function checkVcode(){
	var vcode = $.trim($("#auth_code").val());
	var falg = true;
	if(vcode == null || vcode == "" || vcode == "验证码"){
		layer.tips("请输入验证码", "#auth_code", {tips: [2, "#E34127"],time: 500});
		falg = false;
	}
	return falg;
}

/**
 * 用户登录
 */
function login(){
	if(checkUserName()&&checkPassWord()&&checkVcode()){
		var userName = $.trim($("#username").val());
		var passWord = $.trim($("#password").val());
		var vcode=$.trim($("#auth_code").val());
		$.ajax({
			type : "post",
			url : "/admin/shiro/login",
			async : false,
			data : {
				userName : userName,
				passWord : passWord,
				vcode:vcode
			},
			dataType:"json",
			success : function(data){
				if(data.code== 0){
					layer.msg("登录成功", {icon: 6}, function(){
						location.href =  "/ajax/main.html";
					});
				}else if(data.code==500){
					layer.msg(data.msg, {icon: 5});
				}
				
			}
		});
	}
}
//回车触发登录
function keyLogin(e){
	  var theEvent = window.event || e;
	      var code = theEvent.keyCode || theEvent.which;
	   if (code==13) {  //回车键的键值为13
		   login();  //调用提交登录
	   }
	  }

function PwdLogin() {
    var login = document.getElementsByClassName("login_con");
    login[0].classList.remove("hidden");
    login[0].classList.add("show");
    login[1].classList.remove("show");
    login[1].classList.add("hidden");
    var tags = document.getElementsByClassName("top_tag");
    tags[0].classList.add("active");
    tags[1].classList.remove("active");
    var ad = document.getElementById("AdImg");
    ad.style.height = "558px";
}
function QrcodeLogin() {
    var login = document.getElementsByClassName("login_con");
    login[0].classList.remove("show");
    login[0].classList.add("hidden");
    login[1].classList.remove("hidden");
    login[1].classList.add("show");
    var tags = document.getElementsByClassName("top_tag");
    tags[1].classList.add("active");
    tags[0].classList.remove("active");
    var ad = document.getElementById("AdImg");
    ad.style.height = "407px";
}